class SessionsController < ApplicationController

  def create
    emails=params[:session][:email].downcase
    user=User.find_by(email: emails)
    if user && user.authenticate(params[:session][:password]) #短路表达式
      if(user.activated == true)
        log_in user                                           #登入用户 存储id到session
        params[:session][:remember]=='1' ? rememberme(user) : forget(user) #持久会话与否
        flash.now[:success]='login success'
        # redirect_or_back user
        redirect_to user
      else
        message  = "账户未激活. "
        message += "请检查激活邮件"
        flash[:warning] = message
        redirect_to root_url
      end
    else
			flash.now[:warning]='登陆失败'
			render 'new'
    end

  end

  def new
		
  end

  def destroy
		logout if is_loged_in?
		redirect_to root_url
  end




end
